package day4;

import java.util.Scanner;

import org.junit.Test;

public class count {
	@Test
	public void array() {// 输出数组
		int[] array = new int[5];
		array[0] = 35;
		array[1] = 66;
		array[2] = 54;
		array[3] = 90;
		array[4] = 50;
		System.out.println(array[0] + "," + array[1] + "," + array[2] + "," + array[3] + "," + array[4]);
		for (int i = array.length - 1; i >= 0; i--) {
			System.out.println(array[i] + ",");
		}
	}

	@Test
	public void huiwen() {// 判断是否是回文数
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入字符串：");
		String str = scanner.next();
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i] + " ");
		}
		System.out.println();
		int i = 0;
		boolean isright = false;
		for (i = 0; i < (array.length + 1) / 2; i++) {
			if (array[i] == array[array.length - 1 - i]) {
				isright = true;
			} else {
				isright = false;
				break;
			}
		}
		if (isright == true) {
			System.out.print("字符串是回文数");
		} else {
			System.out.print("字符串不是回文数");

		}
	}

	@Test
	public void tong() {// 计算英文字母，数字，空格，其他字符个数
		int[] count = new int[4];
		char[] ch = null;
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入字符串：");
		String str = scanner.nextLine();
		ch = str.toCharArray();
		for (int i = 0; i < ch.length; i++) {
			System.out.println(ch[i]);
		}
		for (int i = 0; i < ch.length; i++) {
			// char ch = a[i];
			if (ch[i] >= '0' && ch[i] <= '9') {
				count[0]++;
			} else if ((ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z')) {
				count[1]++;
			} else if (ch[i] == ' ') {
				count[2]++;
			} else {
				count[3]++;
			}
		}
		System.out.println("数字有" + count[0] + "个" + "," + "英文字母有" + count[1] + "个" + "," + "空格有" + count[2] + "个" + ","
				+ "其他字符有" + count[3] + "个");
	}

	@Test
	public void compare() {//比较最大数，最小数
		int[] array = new int[] {23,4,56,78,99,22,67};
		//int max = array[1];
		
		for(int i = 0; i < array.length - 1; i++) {
			for(int j = 0; j < array.length - 1 - i; j++) {
				if(array[j] < array[j + 1]) {
					int max = array[j];
					array[j] = array[j + 1];
					array[j + 1] = max;
				}
			}
		}
		System.out.println("最小数是" +array[array.length - 1] + "," + "最大数是" + array[0] );
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
